package com.haiyi.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.haiyi.entity.AiaUser;
import com.haiyi.service.AiaUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * <p> </p>
 *
 * <pre> Created: 2018/11/27 19:17 </pre>
 *
 * @author hlu
 * @version 1.0
 * @since JDK 1.7
 */
@RestController
public class AiaUserController {
    @Autowired
    private AiaUserService aiaUserService;


    @PostMapping("/addUser")
    public boolean addUser(AiaUser user){
       return aiaUserService.insert(user);
    }

    @GetMapping("/login")
    public boolean login(AiaUser user, HttpSession session){
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.eq("username",user.getUsername());
        final AiaUser aiaUser = aiaUserService.selectOne(wrapper);
        if(aiaUser!=null){
            final boolean result = aiaUser.getPassword().equals(user.getPassword());
            if(result){
                session.setAttribute("user",aiaUser);
                return true;
            }
        }
        return false;
    }

}
